Now let's take a look at Chuck Norris move and PC script.
So we put the kick in him on there and we have the ID, so we'll go to move and pick on Chuck Norris.
Open it up.
And then I'm going to close this animation editor so that I have more room to scroll to the top.
I'm already at the top, and we're going to have to add some variables.
We're going to need a variable for our front kick animation.
So I'll say local front kick and M, and that's on the script, right?
So equals we'll do script colon, wait for child kick in.
M And what else we're going to need an animator.
Make sure Chuck Norris is humanoid has an animator let's go ahead and click on that mine does.
If it does not hit the plus sign hit a add an animator.
Sometimes they don't, but mine has one so good local animator we'll do r i NPC that's Chuck Norris,
right?
Or script parent will work too.
That'll get you the i NPC and we've got a humanoid.
Oh, look at that.
We already have the humanoid actually.
So I whom I forgot we got him up here.
Let's do a colon wait for child animator.
Nice.
And what else we're going to need.
We're going to need a front kick track.
So I'll say local front kick track and I will get that when I take my animator colon, do a load animation
and put the front kick and am in the in the animator, which is in the humanoid.
I'm going to get my track back and I'm going to be able to play that track.
We're going to need a sound to.
Let's get the kick working before we get the sound.
But I will put a variable for the sound.
I'll say kick sound.
We might want to make it a general hit sound.
Just make that nil for now.
All right, now we're going to scroll down.
To where we do our while loop.
And this was the loop that we used for Cletus to find the nearest character and then get really close
to them and follow them around.
So we're going to keep that.
We're going to keep that.
We're going to add to it.
Before I add to it, I'm going to make another helper function above that while loop.
Let's say a local function I'm going to call that is within range.
So I want to know.
And Chuck considers himself close enough to do a CEC, or we might want to use this for other things.
So I'm going to keep it kind of general.
The HRP is going to be Chuck's humanoid root part.
The goal?
Well, for our first application, at least, it's going to be the humanoid root part that he wants
to kick.
It'll be a part regardless.
Whoops.
Goal.
And then a comma.
And then I'm going to need a tolerance.
How close is close?
Enough so that he reached his goal?
Like, is he within the range that we want?
And I will just return a calculation and it's going to return the answer of the calculation.
So I'm going to put it inside parentheses to get the humanoid root parts position of chalk.
I'm going to subtract the goal position, probably the enemy humanoid root part.
I'll do this dot mag magnitude, which I always spell wrong.
And if it's less than our tolerance, we're going to assume, hey, he's close enough to kick them and
maybe we'll put this whole thing in parentheses so that you could see that you're returning one single
value.
It's going to be a true or a false.
So we're going to do this calculation.
Right here.
We're going to subtract the HRP from the or the goal from the HRP.
We're going to take the magnitude, which is going to be the distance.
And then we are going to see if it's less than a tolerance, which is a scalar number.
We've got to set that tolerance, though.
And if it is, we're close enough, It's going to be true.
We're going to return true.
Boom.
We're going to do a kick.
Let's go to the top here.
And we'll do variable local, let's say, tall for kicks.
So that's going to be my kick tolerance.
How close do we have to be to the character to do it?
Kick five.
I'll say five studs away.
All right.
They're down here now.
We're chasing them around with this move to let's see when he's within range.
So I'll do local R and G.
I'll keep it.
A very simple variable is going to be local to the loop, and we'll have equal is within range.
We're going to have our i hrp, which is Chuck's humanoid root part.
We're going to have our closest humanoid root part.
That's the goal.
And then we're going to have our tolerance.
We call that what tall for kick cool.
And also remember we're going to be doing damage, right?
We're not just following around.
We're going to be we're going to be kicking them and hurting them.
So we really need the humanoid root part.
Also, let's get that local.
We have the closest HRP Let's get the closest.
HUME Using the closest air.
P So do closest air parent that's going to give us the character of the humanoid root part that we're
close to.
We'll do a colon, find first child humanoid.
All right, now let's do an if statement.
So we'll say if we are within range, right?
And let's make sure the closest humanoid root part exists.
He's not responding or something, right?
He just died.
Now the humanoid root parts gone.
And we'll also check to see if the closest humanoid root parts health is greater than zero.
So it's here and it's also there are some health here.
He's gone.
He might be like responding halfway through the humanoid root parts there, but the humanoid is not
something crazy like that, just being extra special.
Careful.
And then if all those conditions are true, we can go ahead and do our kick.
So we have our kick, not kick sound.
We have our kick front kick track.
That's what we want.
Front, kick, track.
Cole And play.
And since we're doing a kick and we're close, let's go ahead and give him credit for damage.
So do closest HR P No close is humanoid colon Take damage.
Take damage.
Let's make it like 30.
Oh, let's put a variable in there for for the damage, for the kick.
Let's do that.
Let's go up to the top.
Where we declare our variables and we'll have kick damage, local kick damage equals 30, and then we'll
just put that variable down here.
It'll be a little easier to find if you're updating your code and digging around and code.
Right.
So have kick damage, boom.
So we have two small adjustments to make.
One will do right now.
When we made Cletus move to the person that he's following around, we stayed back five studs.
But our tolerance for kick is five studs.
So I'm going to change this to two studs.
So when we move to, we're going to try and get two studs away from the person we're following.
Well, Chuck Norris is going to stop two studs away.
That's going to give us three studs where we could fire off the kick.
Another problem that we're having currently but might not exist when you watch this video is the closest
humanoid dot health when the player dies doesn't quite go down to zero.
It was some update they did recently.
It's like one point something.
Let's just go ahead and do a printout so we could see what that health is.
There is a workaround.
It's a shame we have to do it, but sometimes you have to do that in coding.
Let's get our human health and we'll do closest humanoid dot health.
So let's see what the health is because he's going to keep kicking and charting is going to keep kicking
even though we died.
Let's go to our NPC work and move our spawn location a little closer.
This is the chuck that I showed in the demo.
This is the Chuck Norris that we are working on now, so I want to be closer to him.
Let's hit the play.
Now we're going to have our invincibility bubble up for a little bit.
This little haze goes around.
So you won't take any any damage right away.
Let's go to our view.
That output window get closed.
There we go.
Now we can get some damage.
Boom, boom, boom.
See the house going down?
Went down at 13.
Oh, and he's still kicking, so.
And then we could see that the health was one and one.
I was going to do the diet event check for the diet event in the character that had the closest humanoid
root part.
But, you know, we have to still put the the force on where it kicks them back and it's probably going
to kick them back far enough where it's not going to be an issue.
So I think I'm just going to go with that and we'll monitor the health less than zero to see if it gets
fixed in the next update.
We also have to put a sound on the kick to make it sound cool.
So in the next video, let's go ahead and get started on those other things.